rm(list =ls())
options(scipen=999)
gc()
packages <-c("tidyverse","estimatr","plm","stargazer",
             "fastDummies","ICCbin","ihs","readstata13","xtable",
             "lmtest","sandwich")

new.packages <- packages[!(packages %in% installed.packages()[,"Package"])]
if(length(new.packages)) install.packages(new.packages)

lapply(packages, require, character.only = TRUE)
rm(packages, new.packages)

setwd("PUT YOUR DIRECTORY HERE")
setwd("/Users/hagerans/Dropbox/Research/Polish_priests/8_Replicationn/replication")


## load data sets
surv_global <- readxl::read_xlsx("./Datasets/surveillance_global.xlsx")
protests <- read.csv("./Datasets/protests_acled_2018_collapsed.csv")

## merge
data <- merge(surv_global, protests, by = "iso3")
rm(surv_global, protests)

## rearrange
data <- data%>%
  dplyr::mutate_at(c("A_Political_killing", "B_Disappearance", "C_Torture", 
                     "D_Arbitrary_arrest", "E_Unfair_trial", "F_Surveillance", 
                     "protests"), scale)

## run models
lm_protest <- lm(protests ~ A_Political_killing + B_Disappearance + C_Torture +
                   D_Arbitrary_arrest + E_Unfair_trial + F_Surveillance, data = data)

lm_protest <- coeftest(lm_protest, vcov = vcovHC(lm_protest, type="HC1"))



